﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TCKQKL.FrontEnd.DataModel;
using TCKQKL.FrontEnd.Config;
using TCKQKL.Service.LookupClient;

namespace TCKQKL.FrontEnd.Web.Controls
{
    public partial class InvestorSummary : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LSClient client = new LSClient();
            PersonalHoldingUI personalHolding = client.getPersonalHolding(client.getAccountData(HttpContext.Current.User.Identity.Name).investorId);
            PersonalTradingResultUI personalTradingResult = client.getPersonalTradingResult(client.getAccountData(HttpContext.Current.User.Identity.Name).investorId, false);
            client.Close();
            lblNoAssign.Text = personalHolding.AssignAccounts.Count.ToString();
            lblNoStock.Text = personalHolding.MainAccount.Holding.Count.ToString();
            decimal trading = 0;
            for (int i = 0; i < personalHolding.MainAccount.Holding.Count; i++)
                trading += (personalHolding.MainAccount.Holding[i].Account.tradingAmount + personalHolding.MainAccount.Holding[i].Account.nettingAmount) * personalHolding.MainAccount.Holding[i].Quotes.Closed * 1000;

            lblStockValue.Text = String.Format("{0:0,0}", trading);
            lblTradingAmount.Text = String.Format("{0:0,0}", personalHolding.MainAccount.BankData[0].tradingAmount);
            lblNettingAmount.Text = String.Format("{0:0,0}", personalHolding.MainAccount.BankData[0].nettingAmount);
            lblTotalAmount.Text = String.Format("{0:0,0}", personalHolding.MainAccount.TradingValue + personalHolding.MainAccount.NettingValue + personalHolding.MainAccount.BankData[0].tradingAmount + personalHolding.MainAccount.BankData[0].nettingAmount);
            lblNoOrder.Text = personalTradingResult.MainTradingResult.TradingResults.Count.ToString();
            int noMatch = 0;
            decimal transValue = 0;
            foreach (TradingResultUI myresult in personalTradingResult.MainTradingResult.TradingResults)
            {
                transValue += myresult.SubValue;
                if (myresult.DetailMatched.Count > 0)
                    noMatch++;
            }
            lblNoMatched.Text = noMatch.ToString();
            lblTransactionValue.Text = String.Format("{0:0,0}", transValue);
        }
    }
}